from django.db import models

#导入时间域
from django.utils import timezone

#基类
# class Base(models.Model):
#
# 	#创建时间
# 	create_time = models.DateTimeField(default=timezone.now,null=True)
#
# 	class Meta:
# 		abstract = True

#用户类
class User(models.Model):

	id = models.AutoField(primary_key=True)
	username = models.CharField(max_length=100)
	password = models.CharField(max_length=200)
	phone = models.CharField(max_length=11,default=None)
	email = models.EmailField(default=None)
	num = models.IntegerField(default=0)
	img = models.ImageField(upload_to='static/upload',null=True)
	authority = models.CharField(max_length=32,default=0b110)

	class Meta:
		db_table = "user"


class Node(models.Model):
	node_name = models.CharField(max_length=30)

	class Meta:
		db_table = 'node'


class Access(models.Model):
	user = models.ForeignKey(User,on_delete=models.CASCADE)
	node = models.ForeignKey(Node,on_delete=models.CASCADE)

	class Meta:
		db_table = 'access'


class DingTalkUser(models.Model):
	username = models.CharField(max_length=30)
	unionid = models.CharField(max_length=60)
	dingId = models.CharField(max_length=60)
	openid = models.CharField(max_length=60)

	class Meta:
		db_table = 'dingtalk'


class GiteeUser(models.Model):
	username = models.CharField(max_length=30)
	class Meta:
		db_table = 'gitee'


class Cate(models.Model):
	name = models.CharField(max_length=30)
	pid = models.IntegerField()

	class Meta:
		db_table = 'cate'



class Course(models.Model):
	title = models.CharField(max_length=30,null=True)
	desc = models.CharField(max_length=60,null=True)
	price = models.IntegerField(null=True)
	cid = models.ForeignKey(Cate,on_delete=models.SET_NULL,null=True)
	video = models.CharField(max_length=200,null=True)

	class Meta:
		db_table = 'course'



class Flow(models.Model):
	user = models.ForeignKey(User,on_delete=models.CASCADE)
	course = models.ForeignKey(Course,on_delete=models.CASCADE)

	class Meta:
		db_table = 'flow'


# 打分表
class Score(models.Model):
	user = models.ForeignKey(User,on_delete=models.CASCADE)
	course = models.ForeignKey(Course,on_delete=models.CASCADE)
	score = models.IntegerField()

	class Meta:
		db_table = 'score'




